package com.ruoyi.project.stop.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.stop.domain.WarnConfig;
import com.ruoyi.project.stop.service.IWarnConfigService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
@Api("预警配置管理")
/**
 * 报警阈值设置Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/stop/warn-config")
public class WarnConfigController extends BaseController
{
    private String prefix = "stop/warn-config";

    @Autowired
    private IWarnConfigService warnConfigService;


    @GetMapping()
    public String config()
    {
        return prefix + "/config";
    }

    @ApiOperation("获取预警配置信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        WarnConfig warnConfig = warnConfigService.selectWarnConfigById(id);
        if (warnConfig !=null)
        {
            return success(warnConfig);
        }
        else
        {
            return error("数据不存在");
        }
    }
    /**
     * 查询报警阈值设置列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WarnConfig warnConfig)
    {
        startPage();
        List<WarnConfig> list = warnConfigService.selectWarnConfigList(warnConfig);
        return getDataTable(list);
    }

    /**
     * 导出报警阈值设置列表
     */
    @Log(title = "报警阈值设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WarnConfig warnConfig)
    {
        List<WarnConfig> list = warnConfigService.selectWarnConfigList(warnConfig);
        ExcelUtil<WarnConfig> util = new ExcelUtil<WarnConfig>(WarnConfig.class);
        return util.exportExcel(list, "报警阈值设置数据");
    }

    /**
     * 新增报警阈值设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报警阈值设置
     */

    @Log(title = "报警阈值设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WarnConfig warnConfig)
    {
        return toAjax(warnConfigService.insertWarnConfig(warnConfig));
    }

    /**
     * 修改报警阈值设置
     */

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WarnConfig warnConfig = warnConfigService.selectWarnConfigById(id);
        mmap.put("warnConfig", warnConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存报警阈值设置
     */

    @Log(title = "报警阈值设置", businessType = BusinessType.UPDATE)
    @ApiOperation("修改保存报警阈值设置")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WarnConfig warnConfig)
    {
        return toAjax(warnConfigService.updateWarnConfig(warnConfig));
    }

    /**
     * 删除报警阈值设置
     */

    @Log(title = "报警阈值设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(warnConfigService.deleteWarnConfigByIds(ids));
    }
}
